package com.itheima.d4_algorithm;

import java.util.Arrays;

/**
 * 目标：掌握冒泡排序的编写。
 */
public class Test1 {
    public static void main(String[] args) {
        int[] arr = {8, 5, 2, 1,7,9,6};
        maopao(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void maopao(int[] arr) {
        int a;
        for (int j = 0; j < arr.length-1; j++) {
            for (int i = 0; i < arr.length - 1 -j; i++) {
            if (arr[i] > arr[i + 1]) {
                a = arr[i + 1];
                arr[i + 1] = arr[i];
                arr[i] = a;
            }
        }
        }

        /*for (int i = 0; i < arr.length - 1 - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                a = arr[i + 1];
                arr[i + 1] = arr[i];
                arr[i] = a;
            }
        }
        for (int i = 0; i < arr.length - 1 - 2; i++) {
            if (arr[i] > arr[i + 1]) {
                a = arr[i + 1];
                arr[i + 1] = arr[i];
                arr[i] = a;
            }
        }*/
    }
}
